package com.mouse.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mouse.entity.GeneCategory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mouse.entity.GeneComposition;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author godson
 * @since 2022-08-07
 */
public interface GeneCategoryMapper extends BaseMapper<GeneCategory> {

//    @Select("SELECT gcom_result.*,da.*,ref.*,phe.*,ga.*\n" +
//            "FROM (SELECT gcom.*,dis.* FROM gene_category gca LEFT JOIN genecategory_genecomposition gg ON gca.gid=gg.gid LEFT JOIN gene_composition gcom ON gg.gcid=gcom.gcid \n" +
//            "LEFT JOIN gene_homology gho ON gho.gid=gca.gid LEFT JOIN disease dis ON dis.sid=gho.sid WHERE gca.gid=#{gid}) gcom_result\n" +
//            "LEFT JOIN gene_composition_double_alleles gcomda ON gcom_result.gcid=gcomda.gcid LEFT JOIN double_alleles da on gcomda.did=da.did \n" +
//            "LEFT JOIN gene_composition_reference gcomref ON gcom_result.gcid=gcomref.gcid LEFT JOIN reference ref on gcomref.rid=ref.rid\n" +
//            "LEFT JOIN mouse m ON gcom_result.gcid = m.gcid LEFT JOIN phenotype phe ON m.pid=phe.pid\n" +
//            "LEFT JOIN double_alleles_gene_allele daga ON da.did=daga.did LEFT JOIN gene_allele ga ON ga.aid=daga.aid\n")
//    Page<GeneCategoryResult> getIntegratedResult(Page<GeneCategoryResult> page,@Param("gid") Long gid);


//    @Select("SELECT * FROM gene_category WHERE gene_id=#{gene_id}")
//    Page<GeneCategory> getGeneCategoryByGeneID(Page<GeneCategory> page, @Param("gene_id") Long geneId);
//
//    @Select("SELECT * FROM gene_category WHERE gene_names #{gene_names}")
//    Page<GeneCategory> getGeneCategoryByGeneName(Page<GeneCategory> page, @Param("gene_names") String geneNames);
//
//    @Select("SELECT * FROM gene_category WHERE gene_alias=#{gene_alias}")
//    Page<GeneCategory> getGeneCategoryByGeneAlias(Page<GeneCategory> page, @Param("gene_alias") String geneAlias);
//
//    @Select("SELECT * FROM gene_category WHERE gene_id=#{human_homology}")
//    Page<GeneCategory> getGeneCategoryByGeneHomology(Page<GeneCategory> page, @Param("human_homology") String humanHomology);
//
    @Select("SELECT gc.* FROM gene_composition gcom LEFT JOIN genecategory_genecomposition gcgcom ON gcom.gcid=gcgcom.gcid LEFT JOIN gene_category gc ON gcgcom.gid=gc.gid WHERE gcom.gcid=#{gcid}")
    List<GeneCategory> getGeneCategoryByGcID(@Param("gcid") Long gcid);

    /***
     * 3.2.2.1
     * @param did
     * @return
     */
    @Select("SELECT DISTINCT gc.* FROM\n" +
            "(SELECT gc.* FROM (SELECT gcda.gcid FROM  double_alleles da LEFT JOIN gene_composition_double_alleles gcda ON da.did=gcda.did WHERE da.did=#{did}) res LEFT JOIN gene_composition gc on res.gcid=gc.gcid) gc_res\n" +
            "LEFT JOIN genecategory_genecomposition ggcom ON gc_res.gcid=ggcom.gcid LEFT JOIN gene_category gc ON gc.gid=ggcom.gid")
    List<GeneCategory> getGeneCategoryByDid(@Param("did") Long did);

    @Select("SELECT DISTINCT gc.* FROM gene_allele ga LEFT JOIN double_alleles_gene_allele daga ON ga.aid=daga.aid LEFT JOIN double_alleles da ON daga.did= da.did \n" +
            "LEFT JOIN gene_composition_double_alleles gcda ON gcda.did=da.did LEFT JOIN gene_composition gcom on gcda.gcid=gcom.gcid\n" +
            "LEFT JOIN genecategory_genecomposition gcgcom ON gcgcom.gcid=gcom.gcid LEFT JOIN gene_category gc ON gc.gid=gcgcom.gid\n" +
            "WHERE daga.aid=#{aid}")
    List<GeneCategory> getGeneCategoryByAid(@Param("aid") Long aid);


//    //orm版本
//    public GeneCategory selectByGeneId(Long geneId) {
//        Map<String, Object> map = new HashMap<>();
//        map.put("gid", geneId);
//        return geneCategoryMapper.selectByMap(map).get(0);
//    }
//
//    public GeneCategory selectByName(String name) {
//        Map<String, Object> map = new HashMap<>();
//        map.put("gene_names", name);
//        return geneCategoryMapper.selectByMap(map).get(0);
//
//    }
//
//    public GeneCategory selectByAlias(String alias) {
//        Map<String, Object> map = new HashMap<>();
//        map.put("gene_alias", alias);
//        return geneCategoryMapper.selectByMap(map).get(0);
//    }


}
